﻿Option Explicit On
Option Strict On

Imports System.Data
Imports System.Data.OleDb

Public Class FormPermisos

    Dim miRol As Rol
    Dim ListaPermisos As Permisos
    Dim MiBD As BaseDatos
    Dim DatosLeidos As OleDbDataReader

    Private Sub FormPermisos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Icon = My.Resources.icono_campeonato

        MiBD = New BaseDatos
        DatosLeidos = MiBD.Leer("SELECT Nombre FROM Rol")

        While DatosLeidos.Read
            cbx_Rol.Items.Add(CStr(DatosLeidos(0)))
        End While

        MiBD.CerrarConexion()

    End Sub

    Private Sub cbx_Rol_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbx_Rol.SelectedIndexChanged
        For i As Integer = 0 To 4 Step 1
            clb_Permisos.SetItemChecked(i, False)
        Next

        MiBD = New BaseDatos

        Dim Permisos As OleDbDataReader
        Dim Consulta As String

        Consulta = "SELECT Rol.Nombre, Permisos.* " & _
                   "FROM Permisos RIGHT JOIN Rol ON " & _
                   "Permisos.Id_Permisos = Rol.Id_Permisos" & _
                   " WHERE (((Rol.Nombre)='" & cbx_Rol.Text & "'))"

        Permisos = MiBD.Leer(Consulta)

        While Permisos.Read

            If CBool(Permisos(2)) = True Then
                clb_Permisos.SetItemChecked(0, True)
            End If

            If CBool(Permisos(3)) = True Then
                clb_Permisos.SetItemChecked(1, True)
            End If

            If CBool(Permisos(4)) = True Then
                clb_Permisos.SetItemChecked(2, True)
            End If

            If CBool(Permisos(5)) = True Then
                clb_Permisos.SetItemChecked(3, True)
            End If

            If CBool(Permisos(6)) = True Then
                clb_Permisos.SetItemChecked(4, True)
            End If

        End While

    End Sub
End Class